package com.example.lcqexcel.yuexiu.pdLIb;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.enums.CellExtraTypeEnum;
import com.alibaba.fastjson.JSON;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName PdLibTest
 * @Description
 * @Author lichuanqi
 * @Date 2023/8/11 14:17
 * @Version 1.0
 **/

public class PdLibTest {
    @Test
    public void test() throws FileNotFoundException {
        String fileName = "D:\\test\\yuexiu\\导入数据.xlsx";
        File file = new File(fileName);
        ExcelListener studentListener = new ExcelListener();
        EasyExcel.read(new FileInputStream(file), studentListener).extraRead(CellExtraTypeEnum.MERGE).sheet().doRead();
        List<Map<Integer, Map<Integer, String>>> list = studentListener.getList();
        Map<Integer, String> headTitleMap = studentListener.getHeadTitleMap();
        List<Map<String, String>> mapList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<Integer, Map<Integer, String>> integerMapMap = list.get(i);
            integerMapMap.forEach((k, l) -> {
                Map<String, String> map = new HashMap<>();
                l.forEach((y, z) -> {
                    map.put(headTitleMap.get(y), z);
                });
                mapList.add(map);
            });
        }
        System.out.println(mapList);
        System.out.println("=============================");
        System.out.println(JSON.toJSONString(mapList));
    }
}
